package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.common.exception.CustException;
import com.heima.model.admin.dto.ChannelDto;
import com.heima.model.admin.pojo.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by ZYJ on 2021/5/22 20:25
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理api")
public class ChannelController {
    @Autowired
    private AdChannelService adChannelService;
    @ApiOperation(value = "分页查询")
    @PostMapping("/list")
    public ResponseResult findChannelList(@RequestBody ChannelDto dto){
        return adChannelService.findByNameAndPage(dto);

    }

    @ApiOperation("频道新增")
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody @Validated AdChannel adChannel){
        return adChannelService.insert(adChannel);
    }

    @ApiOperation("频道修改")
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel){
        return adChannelService.updateChannel(adChannel);

    }

    @ApiOperation("频道删除")
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id){
        return this.adChannelService.deleteById(id);
    }

    @ApiOperation(value = "查询频道")
    @GetMapping("/channels")
    public ResponseResult findAll(){
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);

    }
}
